//
// Created by zhuhun on 2024/5/16.
//
#include "main.h"
#include "usart.h"
/**

*Fuction(函数名称):send_position

*To do(功能作用):设置舵机转动角度

*Pin(使用管脚):串口对应的管脚

*var(主要变量):串口选择,Control_Angle控制角度(0~4095)

*hardware(搭载硬件):stm32芯片

*group(组别):电机组

*qq|wechat|tel(选填):q:3038472177;w:222222:t:13292368583

**/
void send_position(unsigned short Control_Angle)
{
    uint8_t buffer[9];
    buffer[0]=0xFF;	//header byte
    buffer[1]=0xFF;	//header byte
    buffer[2]=0xFE;	//motor id
    buffer[3]=0x05;	//length
    buffer[4]=0x03;	//Reg Write:0x04
    buffer[5]=0X08;
    buffer[6]=Control_Angle;
    buffer[7]=Control_Angle>>8;
/* check */
    buffer[8]=~(buffer[2]+buffer[3]+buffer[4]+buffer[5]+buffer[6]+buffer[7]);
    HAL_UART_Transmit(&huart1,buffer,9,0xffff);
    buffer[0]=0xFF;	//header byte
    buffer[1]=0xFF;	//header byte
    buffer[2]=0xFE;	//motor id
    buffer[3]=0x05;	//length
    buffer[4]=0x03;	//Reg Write:0x04
    buffer[5]=0X1E;	//goal position reg address
    buffer[6]=4000;
    buffer[7]=4000>>8;
    /* check */
    buffer[8]=~(buffer[2]+buffer[3]+buffer[4]+buffer[5]+buffer[6]+buffer[7]);

    HAL_UART_Transmit(&huart1,buffer,9,0xffff);
}